<?php
declare (strict_types = 1);

namespace app\files\controller;

use think\exception\ValidateException;
use think\facade\Request;

class Uploads
{
    //
    public function upload(\think\Request $request)
    {
        $type = $request->post("type");
//        $file[] = request()->file();
        $file[] = $request->file('image');
//        $fileSize = 1024 * 1024 * 6;

//        print_r($file);
        foreach ($file as $val)
        {
            try {
//                validate(['fileExt:jpg'])->check($val);

                $savename = \think\facade\Filesystem::putFile( $type, $val);

                return json([
                    'msg'=>'上传成功',
                    'data'=>$savename,
                ]);
            }catch (ValidateException $e){
                return json([
                   'msg'=>'上传失败'
                ]);
//                $error[] = [
//                    'name'=>$val->getOriginalName(),
//                    'msg'=>$e->getMessage(),
//                ];
            }
        }

    }
}
